package model;
import java.util.HashMap;

/**
 * 
 * This class is the Recipe. 
 * @author Roman Pusec, Dennis Goldfinger, Marko Bilic
 *
 */
public class Recipe extends Food {
	
	private HashMap<Food, Integer> foodMap;
	
	/**
	 * Sets the name of the Recipe. 
	 * @param name The name. 
	 */
	public Recipe(String name)
	{
		super(name);
		foodMap = new HashMap<Food, Integer>();
	}
	
	/**
	 * Ads the food with the quantity to the list. 
	 * @param food The food.
	 * @param quantity The quantity of the Food. 
	 */
	public void addFood(Food food, int quantity)
	{
		//I'm not really sure if "food" can be the key, but 
		//that is the only way to remove it later
		if(!foodMap.containsKey(food))
			foodMap.put(food, quantity); 
	}
	
	/**
	 * Removes food from the list. 
	 * @param food The food. 
	 */
	public void removeFood(Food food)
	{
		if(foodMap.containsKey(food))
			foodMap.remove(food);
	}
	
	/**
	 * Returns the list of foods. 
	 * @return The list of foods. 
	 */
	public HashMap<Food, Integer> getFoods()
	{
		return foodMap;
	}
	
	/**
	 * Returns the name of the recipe. 
	 */
	public String getName()
	{
		return this.name;
	}
	
	/**
	 * Sets the name of the recipe. 
	 * @param newName The new name. 
	 */
	public void setName(String newName)
	{
		this.name = newName;
	}
	
	/**
	 * Overridden toString() method which displays the list 
	 * of foods/recipes contained in the given Recipe object. 
	 */
	public String toString()
	{
		String temp = "-- " + this.name + " -- \n" + "Ingredients: ";
		Object[] keys = foodMap.keySet().toArray();
		Object[] values = foodMap.values().toArray();
		
		for(int i = 0; i < foodMap.size(); i++)
		{
			temp += "\n\tFood: " + ((Food)keys[i]).name + "\n\tQuantity: " + values[i];
		}
		
		temp += "\n-----------------------------------------\n";
		
		return temp;
	}
}
